package engine.scene;

import engine.render.Texture;
import engine.render.VertexBuffer;
import math.matrix.mat4f;

public class TriGroup
{
    
    private VertexBuffer vertexBuffer;
    
    private Texture texture;
    //<editor-fold defaultstate="collapsed" desc="getTexture">
    public Texture getTexture()
    {
        return this.texture;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="setTexture">
    public void setTexture(Texture tex)
    {
        this.texture = tex;
    }
    //</editor-fold>
    
    private mat4f matModel; // Will never be null except in error
    //<editor-fold defaultstate="collapsed" desc="setMatrixModel">
    public void setMatrixModel(mat4f matrixModel)
    {
        this.matModel.setTo(matrixModel);
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="getMatrixModel">
    public mat4f getMatrixModel()
    {
        return this.matModel;
    }
    //</editor-fold>
    
    private Tri[] tris; // Will never be null except in error
    //<editor-fold defaultstate="collapsed" desc="getNumTris">
    public int getNumTris()
    {
        return this.tris.length;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="getTriAt">
    public Tri getTriAt(int index)
    {
        return this.tris[index];
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="nullifyTriAt">
    public void nullifyTriAt(int index)
    {
        this.tris[index] = null;
    }
    //</editor-fold>
    
    
    public TriGroup(Tri[] triangles)
    {
        this.tris = triangles;
        this.matModel = new mat4f();
        this.matModel.setToIdentity();
        this.vertexBuffer = new VertexBuffer(triangles);
    }
    
    public TriGroup(TriGroup triGroup)
    {
        this.tris         = triGroup.tris;
        this.matModel     = triGroup.matModel;
        this.texture      = triGroup.texture;
        this.vertexBuffer = triGroup.vertexBuffer;
    }
    
    
    public void render()
    {
        this.texture.bind();
        this.vertexBuffer.render();
        this.texture.unbind();
    }
    
    public void destroy()
    {
        this.tris = null;
        this.matModel = null;
        this.texture = null;
        this.vertexBuffer.destroy();
        this.vertexBuffer = null;
    }
    
}
